﻿using SharpCommon.ORM.Attributes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace SharpCommon.ORM.Common
{
    public class DbEntityUtils
    {
        //public static TableInfo GetTableInfo(object entity,DbOperateType dbOpType)
        //{
           
        //}
        public static string GetTableName(Type classType)
        {
            string strTableName = string.Empty;
            string strEntityName = string.Empty;
            strEntityName = classType.FullName;
            object classAttr = classType.GetCustomAttributes(false)[0];
            if (classAttr is TableAttribute)
            {
                TableAttribute tableAttr = classAttr as TableAttribute;
                strTableName = tableAttr.Name;
            }
            if (string.IsNullOrEmpty(strTableName))
            {
                throw new Exception("􁇎􀖃􃊫:" + strEntityName + "􂲴􁊎􁙗􄝽􃖞[Table(name=\"tablename\")]􄭉􄈟􁡆􁵚􄝽􃖞");
            }
            return strTableName;
        }
        public static string GetColumnName(object attribute)
        {
            string columnName = string.Empty;
            if (attribute is ColumnAttribute)
            {
                ColumnAttribute columnAttr = attribute as ColumnAttribute;
                columnName = columnAttr.Name;
            }
            if (attribute is IdAttribute)
            {
                IdAttribute idAttr = attribute as IdAttribute;
                columnName = idAttr.Name;
            }
            return columnName;
        }
       
    }
}
